﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LP580.CG;

public partial class Manage_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string act = Utils.RQ_str("act");
        if (act.ToLower() == "Out" && !IsPostBack)
        {
            clsAdmin.doLogout();
        }
        //btnHome.OnClientClick = "document.location='../';return false;";
        //lbIP.Text = "您的IP：" + Request.UserHostAddress;
        if (!IsPostBack)
        {
            string strUser = Utils.RQ_str("u");
            tbxName.Text = strUser;
            if (strUser != "")
            {
                form2.DefaultFocus = "tbxPass";
            }
        }
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DealAdminLogin();       
    }

    private void DealAdminLogin()
    {
        clsAdmin adm = new clsAdmin();
        adm.AdminName = tbxName.Text.Replace("'", "");
        adm.AdminPassword = tbxPass.Text.Replace("'", "");
        if (true)
        {
            if (clsAdmin.ValidAdmin(adm.AdminName, adm.AdminPassword))
            {
                clsAdmin.doLogin(adm);
                Response.Redirect("AdminCenter.aspx", true);
            }
            else
            {
                Response.Write("<script>alert('用户名或密码错误！');history.go(-1);</script>");
                Response.End();
            }
        }
        else
        {
            Response.Write("<script>alert('您不是被授权的用户IP！');history.go(-1);</script>");
            Response.End();
        }
    }

    //private bool chkIP()
    //{
    //    bool rv = false;
    //    string usrIP = Request.UserHostAddress;
    //    SiteConfig cfg = new SiteConfig("AllowIP");
    //    if (cfg.KeyValue == "*")
    //    {
    //        rv = true;
    //    }
    //    else
    //    {
    //        string[] arrIP=cfg.KeyValue.Split(',');
    //        for (int i = 0; i < arrIP.Length; i++)
    //        {
    //            if (usrIP == arrIP[i])
    //            {
    //                rv = true;
    //                break;
    //            }
    //        }
    //    }
    //    return rv;
    //}
}